<?php

namespace Models\Api;

use Phalcon\Validation;
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;

class User extends \Models\AbstractModel
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=11, nullable=false)
     */
    protected $id;

    /**
     *
     * @var string
     * @Column(type="string", length=20, nullable=true)
     */
    protected $username;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    protected $password;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    protected $avatar;

    /**
     *
     * @var string
     * @Column(type="string", length=20, nullable=true)
     */
    protected $nickname;

    /**
     *
     * @var string
     * @Column(type="string", length=11, nullable=true)
     */
    protected $phone;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    protected $email;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $user_level_id;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $create_time;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $update_time;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $last_login_time;

    /**
     *
     * @var integer
     * @Column(type="integer", length=1, nullable=true)
     */
    protected $status;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    protected $wechat_openid;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=false)
     */
    protected $share_num;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=false)
     */
    protected $share_order_num;

    /**
     *
     * @var double
     * @Column(type="double", length=10, nullable=false)
     */
    protected $order_price;

    /**
     *
     * @var double
     * @Column(type="double", length=10, nullable=false)
     */
    protected $commission;

    /**
     *
     * @var double
     * @Column(type="double", length=10, nullable=false)
     */
    protected $cash_out_price;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=false)
     */
    protected $cash_out_time;

    /**
     *
     * @var double
     * @Column(type="double", length=10, nullable=false)
     */
    protected $no_cash_out_price;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $p1;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    protected $p2;

    /**
     * Method to set the value of field id
     *
     * @param integer $id
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * Method to set the value of field username
     *
     * @param string $username
     * @return $this
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Method to set the value of field password
     *
     * @param string $password
     * @return $this
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Method to set the value of field avatar
     *
     * @param string $avatar
     * @return $this
     */
    public function setAvatar($avatar)
    {
        $this->avatar = $avatar;

        return $this;
    }

    /**
     * Method to set the value of field nickname
     *
     * @param string $nickname
     * @return $this
     */
    public function setNickname($nickname)
    {
        $this->nickname = $nickname;

        return $this;
    }

    /**
     * Method to set the value of field phone
     *
     * @param string $phone
     * @return $this
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;

        return $this;
    }

    /**
     * Method to set the value of field email
     *
     * @param string $email
     * @return $this
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Method to set the value of field user_level_id
     *
     * @param integer $user_level_id
     * @return $this
     */
    public function setUserLevelId($user_level_id)
    {
        $this->user_level_id = $user_level_id;

        return $this;
    }

    /**
     * Method to set the value of field create_time
     *
     * @param integer $create_time
     * @return $this
     */
    public function setCreateTime($create_time)
    {
        $this->create_time = $create_time;

        return $this;
    }

    /**
     * Method to set the value of field update_time
     *
     * @param integer $update_time
     * @return $this
     */
    public function setUpdateTime($update_time)
    {
        $this->update_time = $update_time;

        return $this;
    }

    /**
     * Method to set the value of field last_login_time
     *
     * @param integer $last_login_time
     * @return $this
     */
    public function setLastLoginTime($last_login_time)
    {
        $this->last_login_time = $last_login_time;

        return $this;
    }

    /**
     * Method to set the value of field status
     *
     * @param integer $status
     * @return $this
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Method to set the value of field wechat_openid
     *
     * @param string $wechat_openid
     * @return $this
     */
    public function setWechatOpenid($wechat_openid)
    {
        $this->wechat_openid = $wechat_openid;

        return $this;
    }

    /**
     * Method to set the value of field share_num
     *
     * @param integer $share_num
     * @return $this
     */
    public function setShareNum($share_num)
    {
        $this->share_num = $share_num;

        return $this;
    }

    /**
     * Method to set the value of field share_order_num
     *
     * @param integer $share_order_num
     * @return $this
     */
    public function setShareOrderNum($share_order_num)
    {
        $this->share_order_num = $share_order_num;

        return $this;
    }

    /**
     * Method to set the value of field order_price
     *
     * @param double $order_price
     * @return $this
     */
    public function setOrderPrice($order_price)
    {
        $this->order_price = $order_price;

        return $this;
    }

    /**
     * Method to set the value of field commission
     *
     * @param double $commission
     * @return $this
     */
    public function setCommission($commission)
    {
        $this->commission = $commission;

        return $this;
    }

    /**
     * Method to set the value of field cash_out_price
     *
     * @param double $cash_out_price
     * @return $this
     */
    public function setCashOutPrice($cash_out_price)
    {
        $this->cash_out_price = $cash_out_price;

        return $this;
    }

    /**
     * Method to set the value of field cash_out_time
     *
     * @param integer $cash_out_time
     * @return $this
     */
    public function setCashOutTime($cash_out_time)
    {
        $this->cash_out_time = $cash_out_time;

        return $this;
    }

    /**
     * Method to set the value of field no_cash_out_price
     *
     * @param double $no_cash_out_price
     * @return $this
     */
    public function setNoCashOutPrice($no_cash_out_price)
    {
        $this->no_cash_out_price = $no_cash_out_price;

        return $this;
    }

    /**
     * Method to set the value of field p1
     *
     * @param integer $p1
     * @return $this
     */
    public function setP1($p1)
    {
        $this->p1 = $p1;

        return $this;
    }

    /**
     * Method to set the value of field p2
     *
     * @param integer $p2
     * @return $this
     */
    public function setP2($p2)
    {
        $this->p2 = $p2;

        return $this;
    }

    /**
     * Returns the value of field id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Returns the value of field username
     *
     * @return string
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Returns the value of field password
     *
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Returns the value of field avatar
     *
     * @return string
     */
    public function getAvatar()
    {
        return $this->avatar;
    }

    /**
     * Returns the value of field nickname
     *
     * @return string
     */
    public function getNickname()
    {
        return $this->nickname;
    }

    /**
     * Returns the value of field phone
     *
     * @return string
     */
    public function getPhone()
    {
        return $this->phone;
    }

    /**
     * Returns the value of field email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Returns the value of field user_level_id
     *
     * @return integer
     */
    public function getUserLevelId()
    {
        return $this->user_level_id;
    }

    /**
     * Returns the value of field create_time
     *
     * @return integer
     */
    public function getCreateTime()
    {
        return $this->create_time;
    }

    /**
     * Returns the value of field update_time
     *
     * @return integer
     */
    public function getUpdateTime()
    {
        return $this->update_time;
    }

    /**
     * Returns the value of field last_login_time
     *
     * @return integer
     */
    public function getLastLoginTime()
    {
        return $this->last_login_time;
    }

    /**
     * Returns the value of field status
     *
     * @return integer
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Returns the value of field wechat_openid
     *
     * @return string
     */
    public function getWechatOpenid()
    {
        return $this->wechat_openid;
    }

    /**
     * Returns the value of field share_num
     *
     * @return integer
     */
    public function getShareNum()
    {
        return $this->share_num;
    }

    /**
     * Returns the value of field share_order_num
     *
     * @return integer
     */
    public function getShareOrderNum()
    {
        return $this->share_order_num;
    }

    /**
     * Returns the value of field order_price
     *
     * @return double
     */
    public function getOrderPrice()
    {
        return $this->order_price;
    }

    /**
     * Returns the value of field commission
     *
     * @return double
     */
    public function getCommission()
    {
        return $this->commission;
    }

    /**
     * Returns the value of field cash_out_price
     *
     * @return double
     */
    public function getCashOutPrice()
    {
        return $this->cash_out_price;
    }

    /**
     * Returns the value of field cash_out_time
     *
     * @return integer
     */
    public function getCashOutTime()
    {
        return $this->cash_out_time;
    }

    /**
     * Returns the value of field no_cash_out_price
     *
     * @return double
     */
    public function getNoCashOutPrice()
    {
        return $this->no_cash_out_price;
    }

    /**
     * Returns the value of field p1
     *
     * @return integer
     */
    public function getP1()
    {
        return $this->p1;
    }

    /**
     * Returns the value of field p2
     *
     * @return integer
     */
    public function getP2()
    {
        return $this->p2;
    }

    /**
     * Validations and business logic
     *
     * @return boolean
     */
    public function validation()
    {
        $validator = new Validation();

        $validator->add(
            'email',
            new EmailValidator(
                [
                    'model'   => $this,
                    'message' => 'Please enter a correct email address',
                ]
            )
        );

        return $this->validate($validator);
    }

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("dev_bigdata");
        $this->hasMany('id', 'Models\Api\Cart', 'user_id', ['alias' => 'Cart']);
        $this->hasMany('id', 'Models\Api\CouponUser', 'user_id', ['alias' => 'CouponUser']);
        $this->hasMany('id', 'Models\Api\Order', 'user_id', ['alias' => 'Order']);
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'user';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return User[]|User
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return User
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

}
